<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AceCRC: /home/brian/src/AceCRC/src/ace_crc/crc16ccitt_byte.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">AceCRC
   &#160;<span id="projectnumber">1.1.1</span>
   </div>
   <div id="projectbrief">Cyclic Redundancy Check (CRC) algorithms (e.g. crc16ccitt, crc32) programmatically converted from C99 code generated by pycrc (https://pycrc.org) to Arduino C++ using namespaces and PROGMEM flash memory.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_7e2fca1243a23cea849d389c30292e19.html">ace_crc</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">crc16ccitt_byte.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="crc16ccitt__byte_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD)</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">  #include &lt;avr/pgmspace.h&gt;</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#else</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">  #include &lt;pgmspace.h&gt;</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="crc16ccitt__byte_8hpp.html">crc16ccitt_byte.hpp</a>&quot;</span> <span class="comment">// header file converted by AceCRC</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &lt;stdint.h&gt;</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160; </div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="keyword">namespace </span>ace_crc {</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="keyword">namespace </span>crc16ccitt_byte {</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160; </div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160; </div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160; </div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="crc16ccitt__bit_8hpp.html#a5a452c1a176f3899bffa9a34fc6143bf">crc_t</a> crc_table[256] PROGMEM = {</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;    0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;};</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160; </div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160; </div>
<div class="line"><a name="l00073"></a><span class="lineno"><a class="line" href="crc16ccitt__byte_8cpp.html#aa38a83b05e8244b0407fa92e349d359a">   73</a></span>&#160;<a class="code" href="crc16ccitt__byte_8hpp.html#acdc1c781a1376f8eb846956ebc7d7a44">crc_t</a> crc_update(<a class="code" href="crc16ccitt__byte_8hpp.html#acdc1c781a1376f8eb846956ebc7d7a44">crc_t</a> crc, <span class="keyword">const</span> <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> data_len)</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;{</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *d = (<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)data;</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    uint8_t tbl_idx;</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160; </div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    <span class="keywordflow">while</span> (data_len--) {</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        tbl_idx = ((crc &gt;&gt; 8) ^ *d) &amp; 0xff;</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;        crc = ((pgm_read_word(crc_table + (tbl_idx))) ^ (crc &lt;&lt; 8)) &amp; 0xffff;</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;        d++;</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;    }</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    <span class="keywordflow">return</span> crc &amp; 0xffff;</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;}</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160; </div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;} <span class="comment">// crc16ccitt_byte</span></div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;} <span class="comment">// ace_crc</span></div>
<div class="ttc" id="acrc16ccitt__bit_8hpp_html_a5a452c1a176f3899bffa9a34fc6143bf"><div class="ttname"><a href="crc16ccitt__bit_8hpp.html#a5a452c1a176f3899bffa9a34fc6143bf">ace_crc::crc16ccitt_bit::crc_t</a></div><div class="ttdeci">uint16_t crc_t</div><div class="ttdoc">The type of the CRC values.</div><div class="ttdef"><b>Definition:</b> <a href="crc16ccitt__bit_8hpp_source.html#l00068">crc16ccitt_bit.hpp:68</a></div></div>
<div class="ttc" id="acrc16ccitt__byte_8hpp_html"><div class="ttname"><a href="crc16ccitt__byte_8hpp.html">crc16ccitt_byte.hpp</a></div><div class="ttdoc">Functions and types for CRC checks.</div></div>
<div class="ttc" id="acrc16ccitt__byte_8hpp_html_acdc1c781a1376f8eb846956ebc7d7a44"><div class="ttname"><a href="crc16ccitt__byte_8hpp.html#acdc1c781a1376f8eb846956ebc7d7a44">ace_crc::crc16ccitt_byte::crc_t</a></div><div class="ttdeci">uint16_t crc_t</div><div class="ttdoc">The type of the CRC values.</div><div class="ttdef"><b>Definition:</b> <a href="crc16ccitt__byte_8hpp_source.html#l00068">crc16ccitt_byte.hpp:68</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>
